package com.lemon.smartsafety.utils.app;

import android.view.Gravity;
import android.widget.Toast;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.IApplication;




/**
 * Created by banXin on 16/3/29.
 * 功能： toast管理
 */
public class ToastUtils {
    private static Toast mToast;


    public static void showButtomToast( String msg) {
        if (mToast == null) getToast();
        mToast.setText(msg);
        mToast.setGravity(Gravity.BOTTOM, 0, IApplication.context().getResources().getDimensionPixelOffset(R.dimen.toast_y));
        mToast.setDuration(Toast.LENGTH_SHORT);
        mToast.show();
    }

    public static void showButtomToast( int messageId) {
        if (mToast == null) getToast();
        mToast.setText(messageId);
        mToast.setGravity(Gravity.BOTTOM, 0, IApplication.context().getResources().getDimensionPixelOffset(R.dimen.toast_y));
        mToast.setDuration(Toast.LENGTH_SHORT);
        mToast.show();
    }

    public static void showMiddleToast( int id) {
        if (mToast == null) getToast();
        mToast.setText(id);
        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.setDuration(Toast.LENGTH_SHORT);
        mToast.show();
    }

    public static void showMiddleToast(String msg) {
        if (mToast == null) getToast();
        mToast.setText(msg);
        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.setDuration(Toast.LENGTH_SHORT);
        mToast.show();
    }

    public void showMiddleToast(String msg, int duration) {
        mToast.setText(msg);
        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.setDuration(duration);
        mToast.show();
    }

    public void showMiddleToastLong(String msg) {
        mToast.setText(msg);
        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.setDuration(Toast.LENGTH_LONG);
        mToast.show();
    }


    private static void getToast() {
        mToast= Toast.makeText(IApplication.context(),"", Toast.LENGTH_SHORT);
    }



    /**
     * Toast
     *
     * @param msg
     */
    public static void toastMsg(String msg) {
        try {
            Toast.makeText(IApplication.context(), msg, Toast.LENGTH_SHORT).show();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * Toast
     *
     * @param res
     */
    public static void toastMsg(int res) {
        try {
            Toast.makeText(IApplication.context(), res, Toast.LENGTH_LONG).show();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
